package com.itheima.jianbing2;

public class Cooker implements Runnable {
    private Desk desk;

    public Cooker(Desk desk) {
        this.desk = desk;
    }

    @Override
    public void run() {
        //while(true) 死循环 条件 当没有数量时  下班
        while (desk.getCount() > 0) {
            //判断是否有煎饼
            synchronized (desk.getObj()) {
                if (desk.isFlag()) {  //有  等着
                    try {
                        desk.getObj().wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } else {
                    //没有   做一个
                    System.out.println("大爷正在做一个煎饼");

                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("做好了");
                    //修改煎饼的状态
                    desk.setFlag(true);
                    //叫人吃
                    desk.getObj().notifyAll();
                }
            }


        }


    }
}
